/*
 * @Description: 
 * @Autor: 商晓彬
 * @Date: 2021-08-20 09:57:42
 * @LastEditors: 商晓彬
 * @LastEditTime: 2021-11-23 18:55:56
 */
import { Component, EventEmitter, Injector, Input, Output, ViewChild } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { BomMakeContentServiceProxy } from '@shared/service-proxies/service-proxies';
import { ModalDirective } from 'ngx-bootstrap';
import * as _ from 'lodash';
import { finalize } from 'rxjs/operators';
import { MessageService } from '@abp/message/message.service';
import { Table } from 'primeng/components/table/table';
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import { HttpClient } from '@angular/common/http';
import { TreeNode } from 'primeng/api';



@Component({
    selector: 'app-bom-watch',
    templateUrl: './bom-watch.component.html',
    styleUrls: ['./bom-watch.component.less']
})
export class BomWatchComponent extends AppComponentBase {
    //引入子组件
    @ViewChild('createOrEditModal') modal: ModalDirective;
    @Input() parentInfo: any;//当前点击节点
    saving = false;
    active = false;
    files1: any;
    constructor(
        injector: Injector,
        private _messageService: MessageService,
        private _httpClient: HttpClient,
        private _bomMakeContentServiceProxy: BomMakeContentServiceProxy
    ) {
        super(injector);
    }
    ngOnInit() {
    }
    show(): void {
        this.active = true;
        this.modal.show();
    }
     //关闭事件
     close(): void {
         this.active = false;
         this.files1 = [];
        this.modal.hide();
     }
     getTreedata() {
        this._bomMakeContentServiceProxy.getBopTreeGrid(
            //2021-10-07 曲冰修改
            this.parentInfo.bopDescId,
            this.parentInfo.lotNoId
        )
            .pipe(finalize(() => { }))
            .subscribe(result => {
                let rs = [];
                let item = { data: undefined, children: [] };
                item.data = result.data;
                item.children = result.children;
                rs.push(item);
                this.expandAll(rs);
                this.files1 = rs;
            });
     }
     expandAll(rs) {
        for (const node of rs) {
            this.TreeExpandRecursive(node, true);
        }
    }
    private TreeExpandRecursive(node: TreeNode, isExpand: boolean) {
        node.expanded = isExpand;
        if (node.children) {
            node.children.forEach((childNode) => {
                this.TreeExpandRecursive(childNode, isExpand);
            });
        } 
    }

}
